package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.FoodKnowledgeDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;

import com.itheima.pojo.Food;
import com.itheima.service.FoodKnowledgeService;
import com.itheima.service.SportKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author xw
 * @date 2020-08-21 17:34
 */
@Service(interfaceClass =FoodKnowledgeService.class)
@Transactional
public class FoodKnowledgeServiceImpl implements FoodKnowledgeService {
    @Autowired
    private FoodKnowledgeDao foodKnowledgeDao;

    //分页
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //根据条件分页查询检查项信息
        Page<Food> page = foodKnowledgeDao.selectByCondition(queryPageBean.getQueryString());
        //构建分页数据返回
        return new PageResult(page.getTotal(),page.getResult());
    }


    //添加
    @Override
    public void add(Food food) {
        foodKnowledgeDao.add(food);
    }

    @Override
    public void deleteById(Integer id) {
        foodKnowledgeDao.deleteById(id);
    }

    @Override
    public Food findById(int id) {
        return foodKnowledgeDao.findById(id);
    }

    @Override
    public void edit(Food food) {
        foodKnowledgeDao.update(food);
    }

    @Override
    public void adds(List<Food> food) {
        if(food!=null&&food.size()>0){
            for (Food food1 : food) {
                foodKnowledgeDao.adds(food1);
            }
        }
    }


}
